package Server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.mysql.jdbc.Connection;

public class MyQuestionnareStart 
{
	static int rowcount,rowcount2;
	/**
	 * catch the current state of questionnare and survey table and send it to gui
	 * @param con2 the connection to DB
	 * @param str string from gui
	 * @return int array to view the questionnare qui
	 */
	public static int[] func(Connection con2, String[] str) 
	{
		int[] iRet = new int[2];
		String sql;
		sql="SELECT * FROM survey";
		Statement stmt1 = null;
		ResultSet rs;	
		try 
		{
			stmt1 = con2.createStatement();				
			rs = stmt1.executeQuery(sql);	
			if (rs.last()) 
			{
				rowcount = rs.getRow();
				rs.beforeFirst(); // not rs.first() because the rs.next() below will move on, missing the first element
			}
			
			iRet[0]=rowcount;
			System.out.print(rowcount);
		 
		
		
		sql="SELECT * FROM questionnare WHERE survey_num="+rowcount;
		stmt1 = con2.createStatement();	
		rs = stmt1.executeQuery(sql);
		if (rs.last()) 
		{
			rowcount2 = rs.getRow();
			rs.beforeFirst(); // not rs.first() because the rs.next() below will move on, missing the first element
		}
	
		System.out.print(rowcount2);
		
		
		iRet[1]=rowcount2;
		}
		
		catch (SQLException e) 
		{
	
			e.printStackTrace();
		}
		
		return iRet;
	}


}
